#ifndef     __AUDIO_BUF_H
#define     __AUDIO_BUF_H

extern "C" {
#include <libavutil/mem.h>
}
#include "../../utils/nocopyable.h"
#include <utility>

struct AudioBuf : private utils::NoCopyable {

public:
    AudioBuf(size_t l = 0) {
        if (l == 0) {
            buf = nullptr;
            len = 0;
        } else {
            buf = (uint8_t *) av_malloc(l);
            len = l;
        }
    }

    bool is_empty() const {
        return buf == nullptr;
    }

    AudioBuf(AudioBuf &&other) {
        buf = other.buf;
        len = other.len;
        pts = other.pts;
        other.buf = nullptr;
    }

    ~AudioBuf() {
        if (buf != nullptr) {
            av_free(buf);
        }
    }

    AudioBuf& operator=(AudioBuf &&other) {
        std::swap(buf, other.buf);
        std::swap(len, other.len);
        std::swap(pts, other.pts);
        return *this;
    }

    uint8_t *buf;
    size_t len;
    int64_t pts;
};


#endif
